package future;

import java.util.concurrent.CountDownLatch;

import org.apache.log4j.Logger;

public class StringInputTask implements Task<String, String> {
    private transient static final Logger log = Logger.getLogger(StringInputTask.class);
    private final String taskName;

    public StringInputTask(final String taskName) {
        this.taskName = taskName;
    }

    @Override
    public String process(String input, CountDownLatch latch) {
        try {
            Thread.sleep(3000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.debug("Done:" + taskName);
        latch.countDown();
        return String.format("Task %s-%s -complete -Yay!", taskName, input);
    }

    @Override
    public String toString() {
        return "StringInputTask{" + "taskName='" + taskName + "\'" + "}";
    }
}
